﻿using MediatR;
using S.Parturition.Domain;
using S.Parturition.Read.API.Application.Command;
using S.Parturition.Read.API.Dto;

namespace S.Parturition.Read.API.Application.CommandHandlers
{
    public class GetLambEarTagHandler : IRequestHandler<GetLambEarTagCommand, List<EarTagDto>>
    {

        private readonly MyDbContext dbContext;

        public GetLambEarTagHandler(MyDbContext dbContext)
        {
            this.dbContext = dbContext;
        }

        public async Task<List<EarTagDto>> Handle(GetLambEarTagCommand request, CancellationToken cancellationToken)
        {
            //获取到种母分娩信息
            var childList = dbContext.LambRegistrationModel.Where(x => x.SheepStatus == false);
            //将Id与耳号赋值
            List<EarTagDto> children = childList.Select(x => new EarTagDto
            {
                Value = x.LambRegistrationId,
                Label = x.EarTag,
            }).ToList();

            return children;
        }
    }
}
